<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24" >
            <h2>产品信息</h2>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerName">
              <j-search-select-tag
                v-model="model.customerName"
                dict="PPM_customerName"
                placeholder="请输入客户名称"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="钳工担当" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="puncher">
              <j-search-select-tag
                v-model="model.puncher"
                dict="PPM_puncher"
                placeholder="请输入钳工担当"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="项目担当" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectLeader">
              <j-search-select-tag
                v-model="model.projectLeader"
                dict="PPM_projectLeader"
                placeholder="请输入项目担当"
              />
            </a-form-model-item>
          </a-col>
          
          <a-col :span="6" >
            <a-form-model-item label="填充系统" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillSystem">
              <j-search-select-tag
                v-model="model.fillSystem"
                dict="PPM_fillSystem"
                placeholder="请输入填充系统"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="难度系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="difficultyFactor">
              <j-search-select-tag
                v-model="model.difficultyFactor"
                dict="PPM_difficultyFactor"
                placeholder="请输入难度系数"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="模具穴数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moldCavityNum">
              <j-search-select-tag
                v-model="model.moldCavityNum"
                dict="PPM_moldCavityNum"
                placeholder="请输入模具穴数"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="机台品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brand">
              <a-input v-model="model.brand" placeholder="请输入机台品牌" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pic">
              <j-image-upload isMultiple  v-model="model.pic" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <h2>模具信息</h2>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="螺杆直径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="screwDiameter">
              <a-input v-model="model.screwDiameter" placeholder="请输入螺杆直径" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="机台吨位报价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quotateMacheTonnage">
              <j-search-select-tag
                v-model="model.quotateMacheTonnage"
                dict="PPM_quotateMacheTonnage"
                placeholder="请输入机台吨位报价"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="机台吨位实际" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualTonnageMache">
              <j-search-select-tag
                v-model="model.actualTonnageMache"
                dict="PPM_actualTonnageMache"
                placeholder="请输入机台吨位实际"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="cht模号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chtModelNum">
              <a-input v-model="model.chtModelNum" placeholder="请输入cht模号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="部品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partName">
              <a-input v-model="model.partName" placeholder="请输入部品名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="material">
              <a-input v-model="model.material" placeholder="请输入材料" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="收缩率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shrinkageRate">
              <a-input v-model="model.shrinkageRate" placeholder="请输入收缩率" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="模具尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moldSize">
              <a-input v-model="model.moldSize" placeholder="请输入模具尺寸" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="成型周期报价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="formCycleQuotation">
              <a-input v-model="model.formCycleQuotation" placeholder="请输入成型周期报价" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="成型周期目标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="targetMoldCycle">
              <a-input v-model="model.targetMoldCycle" placeholder="请输入成型周期目标" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="成型周期实际" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualMoldCycle">
              <a-input v-model="model.actualMoldCycle" placeholder="请输入成型周期实际" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="部品单重报价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unitWeightQuotationComponents">
              <a-input v-model="model.unitWeightQuotationComponents" placeholder="请输入部品单重报价" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="部品单重实际" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actQuotationComponents">
              <a-input v-model="model.actQuotationComponents" placeholder="请输入部品单重实际" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="水口单重报价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quotateSingleWeightWater">
              <a-input v-model="model.quotateSingleWeightWater" placeholder="请输入水口单重报价" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="水口单重实际" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actSingleWeightWater">
              <a-input v-model="model.actSingleWeightWater" placeholder="请输入水口单重实际" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="项目状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qualifiedStatus">
              <j-search-select-tag
                v-model="model.qualifiedStatus"
                dict="PPM_qualifiedStatus"
                placeholder="请输入项目状态"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="现状问题点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentProblem">
              <a-textarea v-model="model.currentProblem" rows="4" placeholder="请输入现状问题点" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6" >
            <a-form-model-item label="对策" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="countermeasures">
              <a-textarea v-model="model.countermeasures" rows="4" placeholder="请输入对策" />
            </a-form-model-item>
          </a-col>
          
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="模具过程表" :key="refKeys[0]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[0]"
          :loading="moldProcessTable.loading"
          :columns="moldProcessTable.columns"
          :dataSource="moldProcessTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"/>
      </a-tab-pane>
      <a-tab-pane tab="试模情况表" :key="refKeys[1]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[1]"
          :loading="trialMoldSituateTable.loading"
          :columns="trialMoldSituateTable.columns"
          :dataSource="trialMoldSituateTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"/>
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { FormTypes,getRefPromise,VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ProjectProgressMainForm',
    mixins: [JEditableTableModelMixin],
    components: {
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 9 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14 },
        },
        model:{
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
        },
        tableKeys:['trialMoldSituate', 'moldProcess', ],
        refKeys: ['trialMoldSituate', 'moldProcess', ],
        activeKey: 'trialMoldSituate',
        // 模具过程表
        moldProcessTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '',
              key: 'projectMainId',
              type: FormTypes.input,
              width:"1px",
              placeholder: '请输入${title}',
              disabled: true,
              defaultValue:'',
            },
            {
              title: '模具过程',
              key: 'moldProcess',
              type: FormTypes.select,
              options:[{'title':'项目启动','value':'项目启动'},
                       {'title':'模具设计','value':'模具设计实际完成时间'},
                       {'title':'模胚订购','value':'模胚订购'},
                       {'title':'热流道订购','value':'热流道订购'},
                       {'title':'钢料','value':'钢料'},
                       {'title':'模具加工','value':'模具加工'},
                      ],
              width:"200px",
              placeholder: '请选择${title}',
              defaultValue:'',
            },
            {
              title: '计划时间',
              key: 'projectStartTimePlan',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '实际时间',
              key: 'projectStartTimeAct',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '差值时间',
              key: 'projectStartTimeDiff',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            // {
            //   title: '模具设计计划完成时间',
            //   key: 'moldStartTimePlan',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模具设计实际完成时间',
            //   key: 'moldStartTimeAct',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模具设计完成实际差值',
            //   key: 'moldStartTimeDiff',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模胚计划订购到厂时间',
            //   key: 'moldBaseOrderPlan',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模胚实际订购到厂时间',
            //   key: 'moldBaseOrderAct',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模胚实际订购到厂时间差值',
            //   key: 'moldBaseOrderDiff',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '热流道计划订购到厂时间',
            //   key: 'hotRunnerPlanTime',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '热流道实际订购到厂时间',
            //   key: 'hotRunnerActTime',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '热流道实际订购到厂时间差值',
            //   key: 'hotRunnerDiffTime',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '钢料计划时间',
            //   key: 'steelOrderPlan',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '钢料实际时间',
            //   key: 'steelActPlan',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '钢料实际时间差值',
            //   key: 'steelActPlanDiff',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模具加工计划时间',
            //   key: 'moldProcessPlanTime',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模具加工实际时间',
            //   key: 'moldProcessActTime',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            // {
            //   title: '模具加工实际时间差值',
            //   key: 'moldProcessDiffTime',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue:'',
            // },
            {
              title: '现状问题',
              key: 'currentProblems',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '对策',
              key: 'countermeasures',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
          ]
        },// 试模情况表
        trialMoldSituateTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '',
              key: 'projectMainId',
              type: FormTypes.input,
              width:"0.000001px",
              placeholder: '请输入${title}',
              disabled: true,
              defaultValue:'',
            },
            {
              title: '试模次数',
              key: 'moldTrialsNum',
              type: FormTypes.select,
              dictCode: 'PPM_moldTrialsNum',
              options:[{'title':'T0','value':'T0'},
                       {'title':'T1','value':'T1'},
                       {'title':'T2','value':'T2'},
                       {'title':'T3','value':'T3'},
                       {'title':'T4','value':'T4'},
                       {'title':'T5','value':'T5'},
                       {'title':'T6','value':'T6'},
                       {'title':'T7','value':'T7'},
                       {'title':'T8','value':'T8'},
                       {'title':'T9','value':'T9'},
                       {'title':'T10','value':'T10'}
                      ],
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '试模计划日期',
              key: 'moldTrialsPlanData',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '试模实际日期',
              key: 'moldTrialsActDate',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '试模质量目标',
              key: 'moldQualityPlan',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '试模质量实际',
              key: 'moldQualityAct',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: 'FAI初次提交物要求',
              key: 'faiPlan',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: 'FAI初次提交物实际',
              key: 'faiAct',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '内部合格计划',
              key: 'internalQualifiedPlan',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '内部合格实际',
              key: 'internalQualifiedAct',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '客户合格要求',
              key: 'customerQualifiedPlan',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '客户合格实际',
              key: 'customerQualifiedAct',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '状态',
              key: 'status',
              type: FormTypes.select,
              dictCode: "PPM_status",
              options:[{'title':'合格','value':'合格'},{'title':'不合格','value':'不合格'}],
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '手掌完成时间',
              key: 'palmCompleteTime',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '现状问题点',
              key: 'currentIssues',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '对策',
              key: 'countermeasures',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '预计合格时间',
              key: 'expectedQualifiedTime',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '模具付款状态',
              key: 'moldPaymentStatus',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '模具计划付款时间',
              key: 'moldPlannedPaymentTime',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
          ]
        },
        url: {
          add: "/ch/projectProgressMain/add",
          edit: "/ch/projectProgressMain/edit",
          queryById: "/ch/projectProgressMain/queryById",
          trialMoldSituate: {
            list: '/ch/projectProgressMain/queryTrialMoldSituateByMainId'
          },
          moldProcess: {
            list: '/ch/projectProgressMain/queryMoldProcessByMainId'
          },
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
    },
    methods: {
      addBefore(){
        this.trialMoldSituateTable.dataSource=[]
        this.moldProcessTable.dataSource=[]
      },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        this.$nextTick(() => {
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.trialMoldSituate.list, params, this.trialMoldSituateTable)
          this.requestSubTableData(this.url.moldProcess.list, params, this.moldProcessTable)
        }
      },
      //校验所有一对一子表表单
      validateSubForm(allValues){
          return new Promise((resolve,reject)=>{
            Promise.all([
            ]).then(() => {
              resolve(allValues)
            }).catch(e => {
              if (e.error === VALIDATE_NO_PASSED) {
                // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
                this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
              } else {
                console.error(e)
              }
            })
          })
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          trialMoldSituateList: allValues.tablesValue[0].values,
          moldProcessList: allValues.tablesValue[1].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },

    }
  }
</script>

<style scoped>
</style>